package com.chenqq;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.FragmentTransaction;

import android.os.Bundle;
import android.os.Environment;
import android.util.Log;
import android.view.View;
import android.widget.FrameLayout;

import com.bumptech.glide.load.DecodeFormat;
import com.suntop.carousel.qlmediaplay.R;
import com.suntop.carousel.qlmediaplay.banner.NewFragmentBanner;
import com.suntop.carousel.qlmediaplay.banner.NewSingleBanner;
import com.suntop.carousel.qlmediaplay.bean.Option;
import com.suntop.carousel.qlmediaplay.field.Field_Banner;
import com.suntop.carousel.qlmediaplay.field.Field_Scale;
import com.suntop.carousel.qlmediaplay.media.IMediaPlayEventListener;
import com.suntop.carousel.qlmediaplay.picture.QLPictureView;
import com.suntop.carousel.qlmediaplay.video.cover.ImageCover;
import com.suntop.carousel.qlmediaplay.video.player.AndroidMediaPlayer;
import com.suntop.carousel.qlmediaplay.video.player.QLVideoView;
import com.suntop.carousel.qlmediaplay.video.player.QNMediaPlayer;

import java.util.ArrayList;

public class MainActivity extends AppCompatActivity {

//    private QLVideoView qlPictureView;
    private FrameLayout qlVideoView;
    private FrameLayout frameLayout;
    private ViewPagerFragment viewPagerFragment;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();

    }

    private void initView() {
        frameLayout = findViewById(R.id.fb_video);
        addFragment(1);
    }

    private void addFragment(int i) {
        viewPagerFragment = ViewPagerFragment.newInstance(i);
        FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
        fragmentTransaction.replace(frameLayout.getId(), viewPagerFragment);
        fragmentTransaction.commitNowAllowingStateLoss();
    }

    private void creaFragment(){
        if (viewPagerFragment!=null) {
            FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
            fragmentTransaction.remove(viewPagerFragment);
            fragmentTransaction.commitNowAllowingStateLoss();
            viewPagerFragment.onDestroy();
        }
    }
    @Override
    protected void onStart() {
        super.onStart();
//        ArrayList<Option> urls = new ArrayList<>();
//        Option option = new Option();
//        option.setPath("/storage/emulated/0/Android/data/com.suntop.wisdomads/files/Download/7_new.jpg");
//        option.setDelayTime(5000);
//        option.setDecodeFormat(DecodeFormat.PREFER_RGB_565);
//        option.setScaleType(Field_Scale.Scale_Match);
//        option.setLoop(false);
//        urls.add(option);
//
//        Option option2=new Option();
//        option2.setPath("http://le.sycdn.kuwo.cn/80d4a48946a489e745ba4ca2385e139a/6281a449/resource/m2/2/73/2564391222.mp4");
//        option2.setDelayTime(5000);
//        option2.setDecodeFormat(DecodeFormat.PREFER_RGB_565);
//        option2.setScaleType(Field_Scale.Scale_Match);
//        option2.setLoop(false);
//        urls.add(option2);
//
//
//        Option option1 = new Option();
//        option1.setPath("http://win.web.nf03.sycdn.kuwo.cn/bb3a37cdadd2866b7e5e1a46157009b4/6281a530/resource/m1/62/88/3855040819.mp4");
//        option1.setDelayTime(5000);
//        option1.setDecodeFormat(DecodeFormat.PREFER_RGB_565);
//        option1.setScaleType(Field_Scale.Scale_Match);
//        option1.setLoop(false);
//        urls.add(option1);
//
//
//        Option option4 = new Option();
//        option4.setPath("sdcard/2.mp4");
//        option4.setDelayTime(5000);
//        option4.setDecodeFormat(DecodeFormat.PREFER_RGB_565);
//        option4.setScaleType(Field_Scale.Scale_Match);
//        option4.setLoop(false);
//        urls.add(option4);
//
//
//
//        Option option5 = new Option();
//        option5.setPath("sdcard/海洋.mov");
//        option5.setDelayTime(5000);
//        option5.setDecodeFormat(DecodeFormat.PREFER_RGB_565);
//        option5.setScaleType(Field_Scale.Scale_Match);
//        option5.setLoop(false);
//        urls.add(option5);
//        qlVideoView.addResource(urls);

    }

    public void startPlay(View view) {
//        qlVideoView.startPlay();
//        qlVideoView.startPlayNow();
    }

    public void pausePlay(View view) {
//        qlVideoView.pausePlay();
//        qlVideoView.pausePlayNow();
    }

    public void stopPlay(View view) {
//        qlVideoView.stopPlayNow();
    }

    public void releasePlay(View view) {
        creaFragment();
//
//        qlVideoView.release();
    }

    public void recreatPlay(View view) {
        addFragment(1);
    }
}